package internal

import (
	"math"
	"os"
	"strconv"
)

func CreatePath(dir string) error {
	if err := os.MkdirAll(dir, 0711); err != nil {
		return err
	}
	return nil
}

func BytesToSize(length int64) string {
	if length == 0 {
		return "0 Bytes"
	}

	var k = 1024
	var sizes = []string{"Bytes", "KB", "MB", "GB", "TB"}

	i := math.Floor(math.Log(float64(length)) / math.Log(float64(k)))
	r := float64(length) / math.Pow(float64(k), i)
	return strconv.FormatFloat(r, 'f', 3, 64) + " " + sizes[int64(i)]
}
